﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using PGI.EN.Inventario;

namespace PGI.AD.Inventario
{
    public class InventarioProductoDetalleAd
    {
        public static List<InventarioProductoDetalleEn> SelInventarioDetalleProducto(int _productoID)
        {
            SqlCommand command = null;
            SqlConnection connection = null;
            SqlDataReader reader = null;

            string sql = "TrnMovInventarioDetalleProducto";

            try
            {
                connection = DataBaseFactory.SqlOpenDatabase("PGI");

                command = new SqlCommand(sql, connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("@ProductoID", _productoID);

                reader = command.ExecuteReader();

                List<InventarioProductoDetalleEn> lstInvVentasDetEn = new List<InventarioProductoDetalleEn>();

                InventarioProductoDetalleEn InvVentasDetEn = null;

                while (reader.Read())
                {
                    InvVentasDetEn = new InventarioProductoDetalleEn();
                    InvVentasDetEn.ProductoID = reader.IsDBNull(0) ? 0 : Convert.ToInt32(reader.GetValue(0));
                    InvVentasDetEn.TallaID = reader.IsDBNull(1) ? 0 : Convert.ToInt32(reader.GetValue(1));
                    InvVentasDetEn.TallaDes = reader.IsDBNull(2) ? string.Empty : reader.GetString(2);
                    InvVentasDetEn.ColorID = reader.IsDBNull(3) ? 0 : Convert.ToInt32(reader.GetValue(3));
                    InvVentasDetEn.ColorDes = reader.IsDBNull(4) ? string.Empty : reader.GetString(4);
                    InvVentasDetEn.MaterialID = reader.IsDBNull(5) ? 0 : Convert.ToInt32(reader.GetValue(5));
                    InvVentasDetEn.MaterialDes = reader.IsDBNull(6) ? string.Empty : reader.GetString(6);
                    InvVentasDetEn.TemporadaID = reader.IsDBNull(7) ? 0 : Convert.ToInt32(reader.GetValue(7));
                    InvVentasDetEn.TemporadaDes = reader.IsDBNull(8) ? string.Empty : reader.GetString(8);
                    InvVentasDetEn.Stock = reader.IsDBNull(9) ? 0 : Convert.ToInt32(reader.GetValue(9));
                    InvVentasDetEn.Costo_Unitario = reader.IsDBNull(10) ? 0 : Convert.ToDouble(reader.GetValue(10));
                    InvVentasDetEn.Precio_Venta = reader.IsDBNull(11) ? 0 : Convert.ToDouble(reader.GetValue(11));
                    

                    lstInvVentasDetEn.Add(InvVentasDetEn);
                }

                return lstInvVentasDetEn;
            }

            catch (SqlException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            finally
            {
                if (reader != null)
                    reader.Close();
                DataBaseFactory.SqlCloseDatabase("PGI");
            }
        }
    }
}
